import { configureStore } from '@reduxjs/toolkit'
import userReducer from './userSlice';
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';

// Redux总store
const store = configureStore({
    reducer: {
        user: userReducer,
    }
});

export default store;

// 推断state、dispatch类型
export type RootStateType = ReturnType<typeof store.getState>;
export type AppDispatchType = typeof store.dispatch;

// 导出类型推断hook
export const useAppDispatch: () => AppDispatchType = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootStateType> = useSelector;